package com.cqupt.scanning.system.file.helper;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.cqupt.scanning.system.admin.entity.FeatureData;
import com.cqupt.scanning.system.admin.entity.PatientFoot;
import com.cqupt.scanning.system.file.helper.utils.TimeFormatUtil;
import com.cqupt.scanning.system.statistics.entity.CalculatedDataFoot1;
import com.cqupt.scanning.system.statistics.service.CalculatedDataFoot1Service;
import com.cqupt.scanning.system.utils.communication.Message;
import com.cqupt.scanning.system.utils.communication.Suggestion;
import com.cqupt.scanning.system.utils.communication.WebSocketServer;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @Data: 2021/7/25 15:04
 * @Author: 宋宝梁
 */
@Component
@Scope("prototype")
public class GenerateFootPDF {


    @Autowired
    private FilePathConfig filePathConfig;

    @Autowired
    private CalculatedDataFoot1Service calculatedDataFoot1Service;

    private PatientFoot patient;
    private FeatureData featureData;
    // 步态分析模板名字
    private String gaitTemplate;
    // 平衡分析模板名字
    private String balanceTemplate;
    // 报告输出的路径的根目录
    private String outFile;
    // 生成报告的名字(格式：yyyyMMddhhmmss-步态分析-name.pdf)
    private String gaitPDFName;
    // 生成报告的名字(格式：yyyyMMddhhmmss-平衡分析-name.pdf)
    private String blancePDFName;
    // 图片数据
    private Map<String, Object> pictureData;

    public String getGaitPDFName() {
        return gaitPDFName;
    }

    public String getBlancePDFName() {
        return blancePDFName;
    }

    public Map<String, String> execute(PatientFoot patient, FeatureData featureData,
                                       String gaitTemplate, String balanceTemplate, String outFile, Map<String, Object> pictureData) throws IOException, DocumentException {
        this.patient = patient;
        this.featureData = featureData;
        this.gaitTemplate = gaitTemplate;
        this.balanceTemplate = balanceTemplate;
        this.outFile = outFile;
        this.pictureData = pictureData;
        DataSet dataSet = new DataSet();
        Map<String, String> dataMapOfGait = dataSet.getDataMapOfGait(patient, featureData); // 生成步态分析数据集
        Map<String, String> dataMapOfBalance = dataSet.getDataMapOfBalance(patient); // 生成平衡分析数据集
//        getSuggestionByNet(dataMapOfGait, dataMapOfBalance, pictureData); // 获取手动建议

        CalculatedDataFoot1 calculatedDataFoot1 = new CalculatedDataFoot1();

        BeanUtil.copyProperties(featureData, calculatedDataFoot1);
        BeanUtil.copyProperties(patient, calculatedDataFoot1);
        BeanUtil.copyProperties(dataMapOfGait, calculatedDataFoot1,"id");
        BeanUtil.copyProperties(dataMapOfBalance, calculatedDataFoot1,
                "id","name","sex","birthDate","heigth","weigth","phone");
        BeanUtil.copyProperties(pictureData, calculatedDataFoot1,
                "id","name","sex","birthDate","heigth","weigth","phone");

        calculatedDataFoot1Service.save(calculatedDataFoot1);

        String strTime = TimeFormatUtil.getStrTime(TimeFormatUtil.ONE);
        String gaitAnalysisReportPath = printGaitAnalysisReport(dataMapOfGait, strTime);
        String balanceAnalysisReportPath = printBalanceAnalysisReport(dataMapOfBalance, strTime);
        Map<String, String> pathMap = new HashMap<>();
        pathMap.put("gaitPath", gaitAnalysisReportPath);
        pathMap.put("balancePath", balanceAnalysisReportPath);
        pathMap.put("outFilePath", outFile + File.separator + strTime);
        return pathMap;
    }

    /**
     * 打印步态分析报告
     * @param dataMap
     * @param strTime
     * @return
     */
    private String printGaitAnalysisReport(Map<String, String> dataMap, String strTime) throws IOException, DocumentException {
        String savePath = null;
        FileOutputStream fos = null;
        InputStream is = null;
        PdfReader reader = null;
        ByteArrayOutputStream baos = null;
        PdfStamper stamp = null;
        Document doc = null;
        try  {
            savePath = this.outFile + File.separator + strTime;
            File pdfPath = new File(savePath);
            if (!pdfPath.exists()) pdfPath.mkdirs();
            StringBuilder sb = new StringBuilder();
            gaitPDFName = sb.append(strTime).append("-步态分析-").append(patient.getName()).append(".pdf").toString();
            fos = new FileOutputStream(savePath + File.separator + gaitPDFName); // 报告生成位置
            is = this.getClass().getResourceAsStream("/static/" + this.gaitTemplate); // 读取步态分析模板
            reader = new PdfReader(is);
            baos = new ByteArrayOutputStream();
            stamp = new PdfStamper(reader,baos);
            AcroFields form = stamp.getAcroFields();
            setFieldForGait(stamp, form, dataMap);
            stamp.setFormFlattening(true);
            stamp.close();
            doc = new Document();
            PdfCopy pdfCopy = new PdfCopy(doc, fos);
            doc.open();
            // 步态分析报告打印4页
            for (int i=1; i<=4; i++) {
                PdfImportedPage impPage = pdfCopy.getImportedPage(new PdfReader(baos.toByteArray()), i);
                pdfCopy.addPage(impPage);
            }
        } finally {
            try {
                if (doc != null) doc.close();
                if (baos != null) baos.close();
                if (reader != null) reader.close();
                if (is != null) is.close();
                if (fos != null) fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        savePath = savePath + File.separator + gaitPDFName;
        return savePath;
    }

    /**
     * 打印平衡分析报告
     * @param dataMap
     * @param strTime
     * @return
     */
    private String printBalanceAnalysisReport(Map<String, String> dataMap, String strTime) throws IOException, DocumentException {
        String savePath = null;
        FileOutputStream fos = null;
        InputStream is = null;
        PdfReader reader = null;
        ByteArrayOutputStream baos = null;
        PdfStamper stamp = null;
        Document doc = null;
        try  {
            savePath = this.outFile + File.separator + strTime;
            File pdfPath = new File(savePath);
            if (!pdfPath.exists()) pdfPath.mkdirs();
            StringBuilder sb = new StringBuilder();
            blancePDFName = sb.append(strTime).append("-平衡分析-").append(patient.getName()).append(".pdf").toString();
            fos = new FileOutputStream(savePath + File.separator + blancePDFName); // 报告生成位置
            is = this.getClass().getResourceAsStream("/static/" + this.balanceTemplate); // 读取平衡分析模板
            reader = new PdfReader(is);
            baos = new ByteArrayOutputStream();
            stamp = new PdfStamper(reader,baos);
            AcroFields form = stamp.getAcroFields();
            setFieldForBalance(stamp, form, dataMap);
            stamp.setFormFlattening(true);
            stamp.close();
            doc = new Document();
            PdfCopy pdfCopy = new PdfCopy(doc, fos);
            doc.open();
            // 平衡测试报告打印7页
            for (int i=1; i<=7; i++) {
                PdfImportedPage impPage = pdfCopy.getImportedPage(new PdfReader(baos.toByteArray()), i);
                pdfCopy.addPage(impPage);
            }
        } finally {
            try {
                if (doc != null) doc.close();
                if (baos != null) baos.close();
                if (reader != null) reader.close();
                if (is != null) is.close();
                if (fos != null) fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        savePath = savePath + File.separator + blancePDFName;
        return savePath;
    }

    /**
     * 为步态分析报告填值
     * @param stamper
     * @param form
     * @param dataMap
     */
    private void setFieldForGait(PdfStamper stamper, AcroFields form, Map<String, String> dataMap) {
        Set<String> it = dataMap.keySet();
        for (String fieldName : it) {
            if (fieldName.equals(filePathConfig.getImageName1())) { // 步态周期检测-左脚
                insertImage(stamper, form, filePathConfig.getImageName1(), filePathConfig.getImagePath1());

            } else if (fieldName.equals(filePathConfig.getImageName2())) { // 步态周期检测-右脚
                insertImage(stamper, form, filePathConfig.getImageName2(), filePathConfig.getImagePath2());

            }
//            else if (fieldName.equals(filePathConfig.getImageName5())) { // 正常步态周期检测图片normal
//                InputStream is = this.getClass().getResourceAsStream("/static/" + filePathConfig.getImagePath5());
//                byte[] imageBytes = StreamConvert.InputStreamToByte(is);
//                insertSameImage(stamper, form, filePathConfig.getImageName5(), imageBytes);
//            }
            else if (fieldName.equals(filePathConfig.getImageName7())) { // cop曲线检测
                insertImage(stamper, form, filePathConfig.getImageName7(), filePathConfig.getImagePath7());
            }else if (fieldName.equals(filePathConfig.getImageName15())) { // MaxFPAleft
                insertSameImage(stamper, form, filePathConfig.getImageName15(), filePathConfig.getImagePath15());
            }else if (fieldName.equals(filePathConfig.getImageName16())) { // MaxFPAright
                insertSameImage(stamper, form, filePathConfig.getImageName16(), filePathConfig.getImagePath16());
            }else if (fieldName.equals(filePathConfig.getImageName17())) { // MinFPAleft
                insertSameImage(stamper, form, filePathConfig.getImageName17(), filePathConfig.getImagePath17());
            }else if (fieldName.equals(filePathConfig.getImageName26())) { // MinFPAright
                insertSameImage(stamper, form, filePathConfig.getImageName26(), filePathConfig.getImagePath26());
            }
            else {
                try {
                    form.setField(fieldName, dataMap.get(fieldName)); // 填文本
                } catch (IOException | DocumentException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 为平衡测试报告填值
     * @param stamper
     * @param form
     * @param dataMap
     */
    private void setFieldForBalance(PdfStamper stamper, AcroFields form, Map<String, String> dataMap) {
        Set<String> it = dataMap.keySet();
        for (String fieldName : it) {
            if (fieldName.equals(filePathConfig.getImageName9())) { // 整体平衡能力分析-balance
                insertImage(stamper, form, filePathConfig.getImageName9(), filePathConfig.getImagePath9());
            } else if (fieldName.equals(filePathConfig.getImageName10())) { // 身体偏移量分析-foreHind
                insertImage(stamper, form, filePathConfig.getImageName10(), filePathConfig.getImagePath10());
            } else if (fieldName.equals(filePathConfig.getImageName11())) { // 身体偏移量分析-inout
                insertImage(stamper, form, filePathConfig.getImageName11(), filePathConfig.getImagePath11());
            } else if (fieldName.equals(filePathConfig.getImageName30())) { // 整体平衡能力分析-averagePercentage
                insertImage(stamper, form, filePathConfig.getImageName30(), filePathConfig.getImagePath30());
            } else if (fieldName.equals(filePathConfig.getImageName31())) { // 整体平衡能力分析-averagePressure
                insertImage(stamper, form, filePathConfig.getImageName31(), filePathConfig.getImagePath31());
            } else if (fieldName.equals(filePathConfig.getImageName32())) { // 偏移量分析-foreFoot
                insertImage(stamper, form, filePathConfig.getImageName32(), filePathConfig.getImagePath32());
            } else if (fieldName.equals(filePathConfig.getImageName33())) { // 偏移量分析-hindFoot
                insertImage(stamper, form, filePathConfig.getImageName33(), filePathConfig.getImagePath33());
            } else if (fieldName.equals(filePathConfig.getImageName34())) { // 偏移量分析-midFoot
                insertImage(stamper, form, filePathConfig.getImageName34(), filePathConfig.getImagePath34());
            } else if (fieldName.equals(filePathConfig.getImageName35())) { // 偏移量分析-otherForeFoot
                insertImage(stamper, form, filePathConfig.getImageName35(), filePathConfig.getImagePath35());
            } else if (fieldName.equals(filePathConfig.getImageName36())) { // 偏移量分析-otherHindFoot
                insertImage(stamper, form, filePathConfig.getImageName36(), filePathConfig.getImagePath33());
            } else if (fieldName.equals(filePathConfig.getImageName37())) { // 偏移量分析-inside
                insertImage(stamper, form, filePathConfig.getImageName37(), filePathConfig.getImagePath37());
            } else if (fieldName.equals(filePathConfig.getImageName38())) { // 偏移量分析-outside
                insertImage(stamper, form, filePathConfig.getImageName38(), filePathConfig.getImagePath38());
            }else if (fieldName.equals(filePathConfig.getImageName8())) { // 足底压力检测-pressure
                insertImage(stamper, form, filePathConfig.getImageName8(), filePathConfig.getImagePath8());
            } else if (fieldName.equals(filePathConfig.getImageName59())) { // 体重分布百分比-weightPercentage_left
                insertImage(stamper, form, filePathConfig.getImageName59(), filePathConfig.getImagePath59());
            } else if (fieldName.equals(filePathConfig.getImageName60())) { // 体重分布百分比-weightPercentage_right
                insertImage(stamper, form, filePathConfig.getImageName60(), filePathConfig.getImagePath60());
            }else if (fieldName.equals(filePathConfig.getImageName40())) { // 快速傅里叶变换-left1fft
                insertImage(stamper, form, filePathConfig.getImageName40(), filePathConfig.getImagePath40());
            }else if (fieldName.equals(filePathConfig.getImageName41())) { // 快速傅里叶变换-left2fft
                insertImage(stamper, form, filePathConfig.getImageName41(), filePathConfig.getImagePath41());
            }else if (fieldName.equals(filePathConfig.getImageName42())) { // 快速傅里叶变换-left3fft
                insertImage(stamper, form, filePathConfig.getImageName42(), filePathConfig.getImagePath42());
            }else if (fieldName.equals(filePathConfig.getImageName43())) { // 快速傅里叶变换-left4fft
                insertImage(stamper, form, filePathConfig.getImageName43(), filePathConfig.getImagePath43());
            }else if (fieldName.equals(filePathConfig.getImageName44())) { // 快速傅里叶变换-left5fft
                insertImage(stamper, form, filePathConfig.getImageName44(), filePathConfig.getImagePath44());
            }else if (fieldName.equals(filePathConfig.getImageName45())) { // 快速傅里叶变换-left6fft
                insertImage(stamper, form, filePathConfig.getImageName45(), filePathConfig.getImagePath45());
            }else if (fieldName.equals(filePathConfig.getImageName46())) { // 快速傅里叶变换-left7fft
                insertImage(stamper, form, filePathConfig.getImageName46(), filePathConfig.getImagePath46());
            }else if (fieldName.equals(filePathConfig.getImageName47())) { // 快速傅里叶变换-left8fft
                insertImage(stamper, form, filePathConfig.getImageName47(), filePathConfig.getImagePath47());
            }else if (fieldName.equals(filePathConfig.getImageName48())) { // 快速傅里叶变换-left9fft
                insertImage(stamper, form, filePathConfig.getImageName48(), filePathConfig.getImagePath48());
            }else if (fieldName.equals(filePathConfig.getImageName49())) { // 快速傅里叶变换-right1fft
                insertImage(stamper, form, filePathConfig.getImageName49(), filePathConfig.getImagePath49());
            }else if (fieldName.equals(filePathConfig.getImageName50())) { // 快速傅里叶变换-right2fft
                insertImage(stamper, form, filePathConfig.getImageName50(), filePathConfig.getImagePath50());
            }else if (fieldName.equals(filePathConfig.getImageName51())) { // 快速傅里叶变换-right3fft
                insertImage(stamper, form, filePathConfig.getImageName51(), filePathConfig.getImagePath51());
            }else if (fieldName.equals(filePathConfig.getImageName52())) { // 快速傅里叶变换-right4fft
                insertImage(stamper, form, filePathConfig.getImageName52(), filePathConfig.getImagePath52());
            }else if (fieldName.equals(filePathConfig.getImageName53())) { // 快速傅里叶变换-right5fft
                insertImage(stamper, form, filePathConfig.getImageName53(), filePathConfig.getImagePath53());
            }else if (fieldName.equals(filePathConfig.getImageName54())) { // 快速傅里叶变换-right6fft
                insertImage(stamper, form, filePathConfig.getImageName54(), filePathConfig.getImagePath54());
            }else if (fieldName.equals(filePathConfig.getImageName55())) { // 快速傅里叶变换-right7fft
                insertImage(stamper, form, filePathConfig.getImageName55(), filePathConfig.getImagePath55());
            }else if (fieldName.equals(filePathConfig.getImageName56())) { // 快速傅里叶变换-right8fft
                insertImage(stamper, form, filePathConfig.getImageName56(), filePathConfig.getImagePath56());
            }else if (fieldName.equals(filePathConfig.getImageName57())) { // 快速傅里叶变换-right9fft
                insertImage(stamper, form, filePathConfig.getImageName57(), filePathConfig.getImagePath57());
            } else if (fieldName.equals(filePathConfig.getImageName58())) { // 前中后足扇形比-offset
                insertImage(stamper, form, filePathConfig.getImageName58(), filePathConfig.getImagePath58());
            }
            else {
                try {
                    form.setField(fieldName, dataMap.get(fieldName)); // 填文本
                } catch (IOException | DocumentException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private void insertImage(PdfStamper stamper, AcroFields form, String imageName, byte[] imagePath) {
        int pageNo = form.getFieldPositions(imageName).get(0).page; // 获取图片所在当前页
        Rectangle signRect = form.getFieldPositions(imageName).get(0).position;
        float x = signRect.getLeft();
        float y = signRect.getBottom();
        try {
            // 读图片
            Image image = Image.getInstance(imagePath);
            // 获取操作的页面
            PdfContentByte under = stamper.getOverContent(pageNo);
            // 根据域的大小缩放图片
            image.scaleToFit(signRect.getWidth(), signRect.getHeight());
            // 添加图片
            image.setAbsolutePosition(x, y);
            under.addImage(image);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }

    private void insertImage(PdfStamper stamper, AcroFields form, String imageName, String imagePath) {
        int pageNo = form.getFieldPositions(imageName).get(0).page; // 获取图片所在当前页
        Rectangle signRect = form.getFieldPositions(imageName).get(0).position;
        float x = signRect.getLeft();
        float y = signRect.getBottom();
        try {
            // 读图片
            Image image = Image.getInstance(imagePath);
            // 获取操作的页面
            PdfContentByte under = stamper.getOverContent(pageNo);
            // 根据域的大小缩放图片
            image.scaleToFit(signRect.getWidth(), signRect.getHeight());
            // 定位图片坐标
            image.setAbsolutePosition(x, y);
            under.addImage(image);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }

    /**
     * 最大、最小步偏脚出现节点插入图片
     * @param stamper
     * @param form
     * @param imageName
     * @param imagePath
     */
    private void insertSameImage(PdfStamper stamper, AcroFields form, String imageName, String imagePath) {

        /*生成左脚步态步偏角指标*/
        double LoadingRatioLeftMean1 = Double.parseDouble(featureData.getLoadingRatioLeftMean())*1000;
        double FootflatRatioLeftMean2 = Double.parseDouble(featureData.getFootflatRatioLeftMean())*1000;
        double PreSwingRatioLeftMean3 = Double.parseDouble(featureData.getPreSwingRatioLeftMean())*1000;
        double SwingRatioLeftMean4 = Double.parseDouble(featureData.getSwingRatioLeftMean())*1000;

        double MaxFPAleft[]={LoadingRatioLeftMean1,FootflatRatioLeftMean2,PreSwingRatioLeftMean3,SwingRatioLeftMean4};
        double MaxFPAlefttemp1=(MaxFPAleft[0]>MaxFPAleft[1])?MaxFPAleft[0]:MaxFPAleft[1];
        double MaxFPAlefttemp2=(MaxFPAlefttemp1>MaxFPAleft[2])?MaxFPAlefttemp1:MaxFPAleft[2];
        double MaxFPAleftmax=(MaxFPAlefttemp2>MaxFPAleft[3])?MaxFPAlefttemp2:MaxFPAleft[3];

        double MaxFPAlefttemp3=(MaxFPAleft[0]<MaxFPAleft[1])?MaxFPAleft[0]:MaxFPAleft[1];
        double MaxFPAlefttemp4=(MaxFPAlefttemp3<MaxFPAleft[2])?MaxFPAlefttemp3:MaxFPAleft[2];
        double MaxFPAleftmin=(MaxFPAlefttemp4<MaxFPAleft[3])?MaxFPAlefttemp4:MaxFPAleft[3];

        /*生成右脚步态步偏角指标*/
        double LoadingRatioRightMean1 = Double.parseDouble(featureData.getLoadingRatioRightMean())*1000;
        double FootflatRatioRightMean2 = Double.parseDouble(featureData.getFootflatRatioRightMean())*1000;
        double PreSwingRatioRightMean3 = Double.parseDouble(featureData.getPreSwingRatioRightMean())*1000;
        double SwingRatioRightMean4 = Double.parseDouble(featureData.getSwingRatioRightMean())*1000;

        double MaxFPAright[]={LoadingRatioRightMean1,FootflatRatioRightMean2,PreSwingRatioRightMean3,SwingRatioRightMean4};
        double MaxFPArighttemp1=(MaxFPAright[0]>MaxFPAright[1])?MaxFPAright[0]:MaxFPAright[1];
        double MaxFPArighttemp2=(MaxFPArighttemp1>MaxFPAright[2])?MaxFPArighttemp1:MaxFPAright[2];
        double MaxFPArightmax=(MaxFPArighttemp2>MaxFPAright[3])?MaxFPArighttemp2:MaxFPAright[3];

        double MaxFPArighttemp3=(MaxFPAright[0]<MaxFPAright[1])?MaxFPAright[0]:MaxFPAright[1];
        double MaxFPArighttemp4=(MaxFPArighttemp3<MaxFPAright[2])?MaxFPArighttemp3:MaxFPAright[2];
        double MaxFPArightmin=(MaxFPArighttemp4<MaxFPAright[3])?MaxFPArighttemp4:MaxFPAright[3];



        for(int i=0;i<MaxFPAleft.length;i++) {
            if (MaxFPAleftmax == MaxFPAleft[i]) {
                insertImage(stamper, form, "leftMax" + (i+1), filePathConfig.getImagePath6());
            }
            if (MaxFPArightmax == MaxFPAright[i]) {
                insertImage(stamper, form, "rightMax" + (i+1), filePathConfig.getImagePath6());
            }
            if (MaxFPAleftmin == MaxFPAleft[i]) {
                insertImage(stamper, form, "leftMin" + (i+1), filePathConfig.getImagePath6());
            }
            if (MaxFPArightmin == MaxFPAright[i]) {
                insertImage(stamper, form, "rightMin" + (i+1), filePathConfig.getImagePath6());
            }
        }
            // 获取图片所在当前页
            int pageNo = form.getFieldPositions(imageName).get(0).page;
            Rectangle signRect = form.getFieldPositions(imageName).get(0).position;
            float x = signRect.getLeft();
            float y = signRect.getBottom();
            try {
                // 读图片
                Image image = Image.getInstance(imagePath);
                // 获取操作的页面
                PdfContentByte under = stamper.getOverContent(pageNo);
                // 根据域的大小缩放图片
                image.scaleToFit(signRect.getWidth(), signRect.getHeight());
                // 定位图片坐标
                image.setAbsolutePosition(x, y);
                under.addImage(image);
            } catch (IOException | DocumentException e) {
                e.printStackTrace();
            }

    }

    /**
     * 获取建议
     * @param dataMapOfGait
     * @param dataMapOfBalance
     */
    private void getSuggestionByNet(Map<String, String> dataMapOfGait, Map<String, String> dataMapOfBalance, Map<String, Object> pictureDataMap) {
        try {
            getPictureData(dataMapOfGait, dataMapOfBalance, pictureDataMap);
            Message message = new Message();
            message.setDataMapOfGait(dataMapOfGait);
            message.setDataMapOfBalance(dataMapOfBalance);
            message.setPictrueData(pictureData);
            message.setCode(20001);
            Suggestion suggestion;
            while (true) {
                if (WebSocketServer.getOnlineCount() == 0) {
                    TimeUnit.SECONDS.sleep(1);
                    continue;
                } else {
                    message.setCode(20001);
                    message.setMessage("病人数据");
                    WebSocketServer.sendInfo("admin", JSONObject.toJSONString(message)); // 有客户连接则发送就绪消息:1.客户收到消息填写建议 2.客户收到消息未填写建议
                    while (true) {
                        suggestion = WebSocketServer.getWebSocketMap().get("admin").getSuggestion(); // 获取当前用户的所填写建议
                        TimeUnit.SECONDS.sleep(1);
                        if (suggestion.getSuggestionOfGait().equals("") && suggestion.getSuggestionOfBalance().equals("")) continue;
                        if (StrUtil.equals(suggestion.getId(), dataMapOfGait.get("id")) && StrUtil.equals(suggestion.getId(), dataMapOfBalance.get("id"))) {
                            dataMapOfGait.put("suggestion", suggestion.getSuggestionOfGait());
                            dataMapOfBalance.put("suggestion", suggestion.getSuggestionOfBalance());
                            suggestion.setSuggestionOfGait("");
                            suggestion.setSuggestionOfBalance("");
                            break;
                        }
                    }
                }
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void getPictureData(Map<String, String> dataMapOfGait, Map<String, String> dataMapOfBalance, Map<String, Object> pictureDataMap) {
        // 最大/小步偏脚出现阶段
        dataMapOfGait.put("max_FPA_left_phase", featureData.getMaxFpaLeftPhase());
        dataMapOfGait.put("max_FPA_right_phase", featureData.getMaxFpaRightPhase());
        dataMapOfGait.put("min_FPA_left_phase", featureData.getMinFpaLeftPhase());
        dataMapOfGait.put("min_FPA_right_phase", featureData.getMinFpaRightPhase());
    }
}
